package com.game.nonperfomers.item;

import java.util.Hashtable;
import java.util.Observable;
import java.util.Observer;

import com.game.nonperfomers.Item;

public class Assignment extends Item implements Observer{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4599146134145682003L;

	/**
	 * 发起人Actor.id
	 */
	public int originator;
	
	/**
	 * 接受者Actor.id
	 */
	public int accept;
	
	/**
	 * 发布时间
	 */
	public long ctime;
	
	/**
	 * 接受时间
	 */
	public long mtime;
	
	/**
	 * 完成时间
	 */
	public long comptime;
	
	/**
	 * 提交时间
	 */
	public long submistime;
	
	/**
	 * 委派的名称
	 */
	public String name;
	
	/**
	 * 委派的描述
	 */
	public String description;
	
	/**
	 * 未接受时候的对白
	 */
	public String requireSay;
	
	/**
	 * 已经接受后的对白
	 */
	public String acceptSay;
	
	/**
	 * 完成后的对白
	 */
	public String completedSay;
	
	private Hashtable<Integer, Integer> goals;
	
	public void setGoals(Integer value){
		 goals = new Hashtable<Integer, Integer>();
		 if(value>0){
			 goals.put(value, 0);
		 }
	}
	/**
	 * 设置任务目标
	 * @param value
	 */
	public void setGoals(String value){
		 goals = new Hashtable<Integer, Integer>();
		 String[] goalarr = value.split(",");
		 for(String goalstr:goalarr){
			 Integer goalid = Integer.parseInt(goalstr);
			 if(goalid>0)
				 goals.put(goalid, 0);
		 }
	}
	
	public void setGoals(Hashtable<Integer, Integer> value){
		 goals = value;
	}
	
	public Hashtable<Integer, Integer> getGoals() {
		return goals;
	}

	/**
	 * 完成目标
	 * @param goal 目标
	 * @param count 次数
	 */
	public synchronized void completedGoals(AssignmentGoal goal,int count) {
		if(this.goals.containsKey(goal.type)){
			if(count<0)
				return;
			this.goals.put(goal.cfg_id, this.goals.get(goal.type)+count);			
		}
		else
		{
			if(count<=0)
				count = 1;
			this.goals.put(goal.cfg_id, count);
		}
	}
	
	@Override
	public void update(Observable o, Object arg) {
		
	}

}
